//
//  pointer.cpp
//  learnC++
//
//  Created by apple on 2018/5/29.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "pointer.hpp"

void test_pointer(){
    
    int value = 5;
    std::cout << &value << "\n"; // prints address of value
    std::cout << value << "\n"; // prints contents of value
    
    int *ptr = &value; // ptr points to value
    std::cout << ptr << "\n"; // prints address held in ptr, which is &value
    std::cout << *ptr << "\n";
    
    //访问系统未分配的地址，会被系统杀掉程序
    
    //null ptr
    float *ptr2 { nullptr };
    
    printf("%p\n",ptr2);
    
    std::nullptr_t ptr3;//空指针类型
    
    //固定指针与指针的细小区别
    int array[5] = { 9, 7, 5, 3, 1 };
    std::cout << sizeof(array) << '\n'; // will print sizeof(int) * array length
    
    int *ptr4 = array;
    std::cout << sizeof(ptr4) << '\n'; // will print the size of a pointer
    
    const char *name = "name";//符号常量的话为不可以修改内容
    std::cout << name << '\n';
    
    const char *name1 = "Alex";
    const char *name2 = "Alex";
    
    printf("%p===%p\n",name1,name2);
}


